
package petrivis.view;

import java.awt.Graphics2D;
import petrivis.model.PetriNet;
import prefuse.Constants;
import prefuse.render.DefaultRendererFactory;
import prefuse.render.EdgeRenderer;
import prefuse.render.LabelRenderer;
import prefuse.render.ShapeRenderer;
import prefuse.visual.VisualItem;

/**
 * Class that manage the Renderers of all the elements of the Petri Net
 * @author Jorge Munoz
 */
public class PNRendererFactory extends DefaultRendererFactory{

    //TODO Edge Arrow and Line selected by user

    private PlaceRenderer placeR;
    private TransRenderer transR;
    private ArcRenderer arcR;
    private ShapeRenderer tokenR;
    private WeightRenderer weightR;

    public PNRendererFactory(){
        //Create a DefaultRendererFactory
        super();

        //Inizializate the Renderers
        placeR = new PlaceRenderer();
        transR = new TransRenderer(PetriNet.NAME_COL);
        arcR = new ArcRenderer(Constants.EDGE_TYPE_LINE,Constants.EDGE_ARROW_FORWARD);
        tokenR = new PlaceRenderer();
        weightR = new WeightRenderer(PetriNet.WEIGHT_COL);

        //Add the renderers for the elements of the Petri Net
        add(PNVisualization.placePred, placeR);
        add(PNVisualization.transPred, transR);
        setDefaultEdgeRenderer(arcR);
        add(PNVisualization.tokensGroupPred, tokenR);
        add(PNVisualization.weightGroupPred,weightR);
    }



    public class PlaceRenderer extends ShapeRenderer {
        public PlaceRenderer(){
            super();
            setBaseSize(30);
        }
        @Override
        public void render(Graphics2D g, VisualItem item) {
            super.render(g, item);
            System.out.println("X: "+item.getX());
            System.out.println("Y: "+item.getY());
        }
    }

    public class TransRenderer extends LabelRenderer{
        public TransRenderer(String field){
            super(field);
            setHorizontalPadding(6);
            setVerticalPadding(6);
        }
        @Override
        public void render(Graphics2D g, VisualItem item) {
            super.render(g, item);
            System.out.println("Size: "+item.getSize());
        }
    }

    public class ArcRenderer extends EdgeRenderer{
        public ArcRenderer(int edgeType, int arrowType){
            super(edgeType,arrowType);
        }
    }

    public class WeightRenderer extends LabelRenderer{
        public WeightRenderer(String field){
            super(field);
            setHorizontalPadding(6);
            setVerticalPadding(6);
        }
    }
}
